//
//  StatusesTopView.swift
//  Microblog
//
//  Created by steaest on 15/8/5.
//  Copyright © 2015年 steaest. All rights reserved.
//

import UIKit
import SDWebImage

class StatusesTopView: UIView {

    //微博数据模型
    var status: Status? {
        didSet {
           if let url = status?.user?.iconURL {
                iconView.sd_setImageWithURL(url)
            }
            memberIconView.image = status?.user?.memberImage
            VipIconView.image = status?.user?.vipImage
            
            nameLabel.text = status?.user?.name ?? ""
            timeLabel.text = "刚刚"
            sourLabel.text = "来自 微博.com"
        }
    }
    
    //构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        backgroundColor = UIColor.clearColor()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 设置界面
    private func setupUI() {
        
        //设置间隔视图
        let segView = UIView()
        segView.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
        addSubview(segView)
        segView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.size.width, height: 10))
        
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourLabel)
        addSubview(memberIconView)
        addSubview(VipIconView)
        
        //自动布局
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: segView, size: CGSizeMake(35, 35), offset: CGPointMake(StatusesCellMargin, StatusesCellMargin))
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPointMake(StatusesCellMargin, 0))
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPointMake(StatusesCellMargin, 0))
        sourLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLabel, size: nil, offset: CGPointMake(StatusesCellMargin, 0))
        memberIconView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: CGPointMake(StatusesCellMargin, 0))
        VipIconView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPointMake(StatusesCellMargin, StatusesCellMargin))
    }
    
    //MARK: - 懒加载控件
    //头像
    private lazy var iconView: UIImageView = UIImageView()
    //姓名
    private lazy var nameLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    //时间
    private lazy var timeLabel: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    //来源
    private lazy var sourLabel: UILabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 9)
    //会员
    private lazy var memberIconView: UIImageView = UIImageView()
    //等级
    private lazy var VipIconView: UIImageView = UIImageView()
}
